import type { PageParam, PageResult } from '@vben/request';
import type { Dayjs } from 'dayjs';

import { requestClient } from '#/api/request';

export namespace CommissionPolicyApi {
  /** 提成策略信息 */
  export interface CommissionPolicy {
    id: number; // 主键ID
    policyCode?: string; // 策略编码
    policyName?: string; // 策略名称
    staffType?: string; // 适用员工类型
    commissionType?: string; // 提成类型
    conditionConfig?: string; // 条件配置(JSON，例如：服务类别=按摩, 金额区间=100-500)
    commissionFormula?: string; // 提成公式(JSON，例如：base_amount * 0.05)
    priority?: number; // 优先级
    startTime: string | Dayjs; // 生效时间
    endTime: string | Dayjs; // 失效时间
    status: string; // 状态
  }
}

/** 查询提成策略分页 */
export function getCommissionPolicyPage(params: PageParam) {
  return requestClient.get<PageResult<CommissionPolicyApi.CommissionPolicy>>('/spa/commission-policy/page', { params });
}

/** 查询提成策略详情 */
export function getCommissionPolicy(id: number) {
  return requestClient.get<CommissionPolicyApi.CommissionPolicy>(`/spa/commission-policy/get?id=${id}`);
}

/** 新增提成策略 */
export function createCommissionPolicy(data: CommissionPolicyApi.CommissionPolicy) {
  return requestClient.post('/spa/commission-policy/create', data);
}

/** 修改提成策略 */
export function updateCommissionPolicy(data: CommissionPolicyApi.CommissionPolicy) {
  return requestClient.put('/spa/commission-policy/update', data);
}

/** 删除提成策略 */
export function deleteCommissionPolicy(id: number) {
  return requestClient.delete(`/spa/commission-policy/delete?id=${id}`);
}


/** 导出提成策略 */
export function exportCommissionPolicy(params: any) {
  return requestClient.download('/spa/commission-policy/export-excel', { params });
}

